<?PHP
session_start();
include("common/connect.php");
include("common/common.php");

function GetTbId( $tbid )
{
	return $tbid;
}

if( !isset($_SESSION["user"]) ) 
{
	$url = "Location:login.php?ref=feedback.php";
	header($url);
}

//$showtype = CheckUrlParamNoDie("showtype");
//$id = SetUrlParamInt("id");
//$opt = CheckUrlParamNoDie( "opt" );
$showtype = trim(CheckUrlParamNoDie( "showtype" ));
$input_tradeid = trim(CheckUrlParamNoDie( "input_tradeid" ));
$tradeid_begin = substr($input_tradeid, 0, 6);
$tradeid_end = substr($input_tradeid, -4);
$nPage = SetUrlParamInt("page");
$opt = CheckUrlParamNoDie("opt");
$id = CheckUrlParamNoDie("id");
if( $nPage < 0 )
	$nPage = 0;

if ($opt == "deal")
{
	$id = SetUrlParamInt( "id" );
	$sql = "update feedback set state=1,opt_time=now(),operater='".$_SESSION["user"]."' where id=$id";
	mysql_query( $sql );
	echo "<script>window.history.back()</script>";
	exit;
}
else if ($opt == "lost")
{
	$id = SetUrlParamInt( "id" );
	$sql = "update feedback set state=2,opt_time=now(),operater='".$_SESSION["user"]."' where id=$id";
	mysql_query( $sql );
	echo "<script>window.history.back()</script>";
	exit;
}
else if ($opt == "reset")
{
	$id = SetUrlParamInt( "id" );
	$sql = "update feedback set state=0,opt_time=now(),operater='".$_SESSION["user"]."' where id=$id";
	mysql_query( $sql );
	if (mysql_affected_rows() == 0)
		echo "<script>alert('操作失败！');";
		
	echo "<script>window.history.back()</script>";
}
else if ($opt == "check")
{
	$id = SetUrlParamInt( "id" );
	$result = mysql_query( "select handle_code from report_items where trade_id like '".$tradeid_begin."%".$tradeid_end."'");
	if (mysql_num_rows($result) > 0)
	{
		$row = mysql_fetch_assoc( $result );
		if ($row["handle_code"] == 2)
			echo "<script>alert(\"此单已经处理！\"); window.history.back();</script>";
		else if ($row["handle_code"] == 3)
			echo "<script>alert(\"漏单！\"); window.history.back();</script>";
	}
	
	echo "<script>window.history.back()</script>";
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
<!--
body,td,th {
	font-family: 宋体;
	font-size: 13px;
	color: #000;
}
body {
	background-color: #FFF;
}
.STYLE1 {
	font-size: x-large;
	font-weight: bold;
}
-->
</style>
<script language="javascript">
function OnFind()
{
	var input_tradeid = document.getElementById("input_tradeid").value;
	window.location.href= "feedback.php?input_tradeid=" + input_tradeid ;
}
</script>
</head>

<body>
<!--<a href="add_trade.php?opt=add">添加记录</a>-->
<div align="center" class="STYLE1">手工申请处理后台</div>
<br>
<table align="center">
	<tr>
    	<td>订单号:<input type="text" onclick="javascript:select();" value="<?PHP echo $input_tradeid; ?>" id="input_tradeid" size="20"/>
    <input type="button" onclick="javascript:OnFind();" value="查找" />&nbsp;&nbsp;
	<a href="feedback.php?page=0&showtype=<?PHP echo $showtype; ?>">首页</a>&nbsp;&nbsp;
	<a href="feedback.php?input_tradeid=<?PHP echo $input_tradeid; ?>&page=<?PHP echo $nPage - 1; ?>">
		<?PHP if ($nPage > 0) echo "<a href='feedback.php?input_tradeid=".$input_tradeid."&page=".($nPage - 1)."&showtype=$showtype'>上一页</a>"; ?>&nbsp;&nbsp;    
	<a href="feedback.php?input_tradeid=<?PHP echo $input_tradeid; ?>&page=<?PHP echo $nPage + 1; ?>&showtype=<?PHP echo $showtype; ?>">下一页</a>&nbsp;&nbsp;
    <a href="feedback.php?showtype=lost">显示漏单</a>&nbsp;&nbsp;<a href="feedback.php">默认显示</a>
	</td>
   </tr>
</table>

<table cellpadding="0" cellspacing="0" border="1" align="center">
	<tr>
    	<td height="25" width="50" align="center">序列号</td>
        <td width="200" align="center">时间</td>
        <td width="166" align="center">支付宝帐号</td>
   	  <td width="121" align="center">订单号</td>
		<td width="121" align="center">备注</td>
      <td width="243" align="center">操作(标志漏单前，一定要确保刚刚更新了后台数据)</td>
    </tr>
<?php

$limit = " limit ". $nPage*20 .",20";
if ($input_tradeid)
	$sql = "select * from feedback where item_url like '".$tradeid_begin."%".$tradeid_end."' or price like '".$tradeid_begin."%".$tradeid_end."' order by id desc";
else if ($showtype == "lost")
	$sql = "select * from feedback where state = 2 order by id desc".$limit;
else
	$sql = "select * from feedback where state = 0 order by id desc".$limit;
	
//$sql = "select * from report_items";
//$sql = "select * from trade where has_return=0".$search."order by id desc".$limit;
$i = 0;
$result = mysql_query( $sql );
while( $result && $row = mysql_fetch_assoc( $result ))
{
	$use_discount = "否";
?>
<tr <?PHP if ($row["state"] == 1) echo "bgcolor='#33CC66'"; else if ($row["state"] == 2) echo "bgcolor='#CC3333'"; else if ($i++ % 2) echo "bgcolor='#CCCCCC'"; ?> >
    <td height="25" width="50" align="center"><?PHP echo $row["id"]; ?></td>
    <td width="200" align="center"><?PHP echo $row["time"]; ?></td>
	<td width="166" align="center"><?PHP echo $row["tb_id"]; ?>&nbsp;</td>
	<td width="121" align="center"><input type="text" onclick="javascript:select();" style="border:none; background:none;" value="<?PHP echo $row["item_url"]; ?>"></td>
    	<td width="121" align="center"><?PHP echo $row["info"]; ?>&nbsp;</td>
    
	<td width="243" align="center" bgcolor="#FFFFFF">
    <?PHP echo "<a href=\"feedback.php?opt=check&id=".$row["id"]."&input_tradeid=".$row["item_url"]."\">自动检测</a>"; ?>&nbsp;
	<?PHP echo "<a href=\"feedback.php?opt=deal&id=".$row["id"]."\">标志已处理</a>"; ?>&nbsp;
    <?PHP echo "<a href=\"feedback.php?opt=lost&id=".$row["id"]."\">标志漏单</a>"; ?>&nbsp;
    <?PHP if ($input_tradeid) echo "<a href=\"feedback.php?opt=reset&id=".$row["id"]."\">重置</a>"; ?>&nbsp;
    </td>
</tr>
<?PHP
}
?>
</table>

</body>
</html>
